package com.ss.project.xia17user.service;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.ss.project.xia17user.config.sys.ConfigKey;
import com.ss.project.xia17user.dao.entity.Config;
import com.ss.project.xia17user.dao.mapper.ConfigMapper;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.Assert;

/**
 * 系统配置
 * @author xia17
 * @date 2020/9/21 17:57
 */
@Service
@Transactional(rollbackFor = Exception.class)
@RequiredArgsConstructor
public class ConfigService {

    private final ConfigMapper configMapper;

    /**
     * 获取配置
     * @return /
     */
    public Config getConfig(ConfigKey key){
        Config config = configMapper.selectOne(Wrappers.<Config>lambdaQuery()
                .eq(Config::getKey, key.name()));
        Assert.notNull(config,"配置在数据库中不存在!");
        return config;
    }

}
